﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using PathologyDAL.Modle;
using PathologyDAL.Service;
using Sunny.UI;

namespace Pathology.Control
{
    public partial class CalculateResultBox : UIUserControl
    {
        public CalculateResultBox()
        {
            InitializeComponent();
        }

        private readonly CalculateResult calculateResult;

        public CalculateResultBox(CalculateResult calculateResult)
        {
            InitializeComponent();
            this.calculateResult = calculateResult;
        }

        private void CalculateResultBox_Paint(object sender, PaintEventArgs e)
        {
            StringFormat format = new StringFormat();
            format.FormatFlags = StringFormatFlags.LineLimit | StringFormatFlags.NoClip;
            
            Graphics g = e.Graphics;
            g.FillEllipse(Color.Lime, new Rectangle(10, 10, 30, 30));
            g.DrawString(
                calculateResult.Tumour.Name,
                new Font("宋体", 15),
                ForeColor,
                new Rectangle(50, 10, 30, 30),
                ContentAlignment.MiddleLeft
            );
            g.DrawLine(ForeColor, 10, 50, Width - 10, 50);
            g.DrawLine(ForeColor, Width/2, 60, Width / 2, Height - 10);

            g.DrawString(
              ShowFitlerName( calculateResult.DeterminantCondition.Name),
              new Font("宋体", 20),
              ForeColor,
              new Rectangle(10, 80, 100, 90),
              ContentAlignment.MiddleLeft
          );
            g.DrawString(
             AttributeValueTool.GetNikeName<Possibility>(calculateResult.Possibility.ToString()),
             new Font("宋体", 40,FontStyle.Bold),
             ForeColor,
             new Rectangle(Width/2+15, 70, 100, 90),
             ContentAlignment.MiddleCenter
         );
        }

        private string ShowFitlerName(string Name)
        {
            StringBuilder sb=new StringBuilder(); 

            int len=Name.Length;
            int row = len / 4;
            int lastrowcount = len % 4;
            
            for (int i = 0; i < row; i++)
            {
                sb.AppendLine(Name.Substring(i*4,4));
               
            }
            if (lastrowcount!=0)
            {
                sb.AppendLine(Name.Substring(row * 4, lastrowcount));
            }

            return sb.ToString();   
            
        
        }
    }
}
